from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save

YEAR_IN_SCHOOL_CHOICES = (
    ('2008', '2008'),
    ('2009', '2009'),
    ('2010', '2010'),
    ('2011', '2011'),
    ('2012', '2012'),
)

SEMESTER_CHOICES = (
    ('1', 'Semester 1'),
    ('2', 'Semester 2'),
    ('3', 'Semester 3'),
)

RATING_CHOICES = (
    (1, '1'),
    (2, '2'),
    (3, '3'),
    (4, '4'),
    (5, '5'),
)

SUBJECT_CHOICES = (
    ('Computing Science',  'Computing Science'),
    ('Accounting and Finance',  'Accounting and Finance'),
    ('Education',  'Education'),
    ('History',  'History'),
    ('Law',  'Law'),
    ('Mathematics',  'Mathematics'),
    ('Statistics',  'Statistics'),
    ('Others', 'Others')
              )

class University(models.Model):
    university_name = models.CharField(max_length=256)

    def __unicode__(self):
        return self.university_name

class UserProfile(models.Model):
    user = models.OneToOneField(User)
    university = models.ForeignKey(University)

class School(models.Model):
    university =  models.ForeignKey(University)
    school_name = models.CharField(max_length=256)
    
    def __unicode__(self):
        return self.school_name

class Course(models.Model):
    school = models.ForeignKey(School)
    course_code = models.CharField(max_length=20)
    course_title = models.CharField(max_length=50)
    course_subject = models.CharField(max_length=30, null=True, choices = SUBJECT_CHOICES)
    course_desc = models.TextField(null=True)
    course_average = models.DecimalField(max_digits = 2, decimal_places=1, null=True)
    course_date = models.DateTimeField(null=True)

    def __unicode__(self):
        return self.course_title

class Comment(models.Model):
    course = models.ForeignKey(Course)
    comment_title = models.CharField(max_length=256)
    comment_year = models.CharField(max_length=4, choices = YEAR_IN_SCHOOL_CHOICES, null=True)
    comment_semester = models.CharField(max_length=20, choices = SEMESTER_CHOICES, null=True)
    comment_tutor = models.CharField(max_length=50, null=True)
    comment_rating = models.IntegerField(max_length=1, choices = RATING_CHOICES)
    comment_text = models.TextField(null=True)
    comment_date = models.DateTimeField(auto_now_add=True)
    
    def __unicode__(self):
        return self.comment_title